package com.ruoyi.common.core.domain.entity;

import java.util.Date;
import java.util.List;
import javax.validation.constraints.*;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.annotation.Excel.Type;
import com.ruoyi.common.annotation.Excels;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.xss.Xss;

/**
 * 用户对象 sys_user
 *
 * @author ruoyi
 */
@Data
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 起始时间
     * 查询时检索使用
     */
    @ApiModelProperty("起始时间 yyyy-MM-dd")
    private String startTime;

    /**
     * 结束时间
     * 查询时检索使用
     */
    @ApiModelProperty("结束时间 yyyy-MM-dd")
    private String endTime;

    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    @ApiModelProperty(value = "用户ID")
    private Long userId;

    @Excel(name = "账号")
    @ApiModelProperty(value = "账号")
    private String userName;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "原密码")
    private String oldPassword;

    @Excel(name = "用户名称")
    @ApiModelProperty(value = "用户名称")
    private String nickName;

    @Excel(name = "部门编号", type = Type.IMPORT)
    @ApiModelProperty(value = "部门ID")
    private Long deptId;

    @ApiModelProperty(value = "角色组id")
    private Long[] roleIds;

    @ApiModelProperty(value = "岗位组id")
    private Long[] postIds;

    @Excel(name = "用户邮箱")
    @ApiModelProperty(value = "用户邮箱")
    private String email;

    @Excel(name = "手机号码")
    @ApiModelProperty(value = "手机号码")
    private String phonenumber;


    @ApiModelProperty(value = "用户类型 1系统用户 2 愉快政 3 愉快办")
    private String userType;

    @ApiModelProperty(value = "工号")
    private String workNo;

    @ApiModelProperty(value = "角色ID")
    private Long roleId;

    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    @ApiModelProperty(value = "0=男,1=女,2=未知")
    private String sex;


    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "帐号状态（0正常 1停用）")
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    @ApiModelProperty(value = "渝快政或渝快办关联id")
    @Excel(name = "渝快政或渝快办关联id")
    private String accountId;

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    private String delFlag;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    @ApiModelProperty(value = "最后登录IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @ApiModelProperty(value = "最后登录时间")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    private Date loginDate;

    /**
     * 部门对象
     */
    @ApiModelProperty(value = "部门对象")
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    private SysDept dept;

    @ApiModelProperty(value = "系统角色对象")
    private List<SysRole> roles;

    @ApiModelProperty(value = "默认角色对象")
    private List<SysRole> defaultRole;


    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}
